# coding=utf-8

import classdef
from tkinter import *
from tkinter.ttk import *
from PIL import Image, ImageTk
import cv2

lst = classdef.lst
window = Tk()
window.title("查找神经元")
window.geometry('800x600+400+50')
lbl = Label(window, text="请输入要查找的神经元", font=('Arial Bold', 11))
lbl.place(x=200,y=0)
#lbl.grid(column=1, row=0)
txt = Entry(window, width=20)
txt.grid(column=0, row=1)
txt.focus()
combo = Combobox(window)
combo['values'] = ('按ID查找', '按单元名称查找', '按档案名称查找', '结构域查找')
combo.current(0)
combo.grid(column=0, row=2)
imlbl = Label(window, text="此处显示图片")
imlbl.place(x=150, y=90)

i = 0


# NMO_149480
def clicked():
    global i
    kw = combo.get()
    if kw == '按ID查找':
        for _, item in enumerate(lst):
            if item.OrgID == txt.get():
                lbl.configure(
                    text=f'ID={item.OrgID}\t单元名称：{item.CName}\t档案名称:{item.AName}\n物种名称:{item.SName}\t株:{item.Strain}\t结构域:{item.SDomains}')
                i = _
                break
        else:
            lbl.configure(text="没有找到目标神经元")
    elif kw == '按单元名称查找':
        for _, item in enumerate(lst):
            if item.CName == txt.get():
                lbl.configure(
                    text=f'ID={item.OrgID}\t单元名称：{item.CName}\t档案名称:{item.AName}\n物种名称:{item.SName}\t株:{item.Strain}\t结构域:{item.SDomains}')
                i = _
                break
        else:
            lbl.configure(text="没有找到目标神经元")
    elif kw == '按档案名称查找':
        for _, item in enumerate(lst):
            if item.AName == txt.get():
                lbl.configure(
                    text=f'ID={item.OrgID}\t单元名称：{item.CName}\t档案名称:{item.AName}\n物种名称:{item.SName}\t株:{item.Strain}\t结构域:{item.SDomains}')
                i = _
                break
        else:
            lbl.configure(text="没有找到目标神经元")
    else:
        for _, item in enumerate(lst):
            if item.SDomains == txt.get():
                lbl.configure(
                    text=f'ID={item.OrgID}\t单元名称：{item.CName}\t档案名称:{item.AName}\n物种名称:{item.SName}\t株:{item.Strain}\t结构域:{item.SDomains}')
                i = _
                break
        else:
            lbl.configure(text="没有找到目标神经元")


def clicked1():
    global i
    i = i + 1
    item = lst[i]
    lbl.configure(text=f'ID={item.OrgID}\t单元名称：{item.CName}\t档案名称:{item.AName}\n物种名称:{item.SName}\t株:{item.Strain}\t结构域:{item.SDomains}')
    if i==1051:
        i=0


def showimg():
    image_name = r'.\img\%s.png'%(lst[i].CName)
    image = cv2.imread(image_name)
    b, g, r = cv2.split(image)
    img = cv2.merge((r, g, b))
    im = Image.fromarray(img)
    imgtk = ImageTk.PhotoImage(image=im)
    imlbl.config(image=imgtk)
    imlbl.image = imgtk


btn = Button(window, text="查找", command=clicked)
btn.grid(column=0, row=3)
btn1 = Button(window, text="查找下一个", command=clicked1)
btn1.grid(column=0, row=4)
btn2 = Button(window, text="展示图片", command=showimg)
btn2.grid(column=0, row=5)

window.mainloop()

# path = r'C:\Users\12274\PycharmProjects\HW1\HW\img\%s.png' % imgname
